<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Auto Width Vertical Menu Bar</title>
<script src="../../widgets/menubar/SpryMenuBar.js" type="text/javascript"></script>
<link href="../../css/samples.css" rel="stylesheet" type="text/css" />
<link href="../../widgets/menubar/SpryMenuBarVertical.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--
.clearAll {
	clear: both;
}
.sidebar {
	/*width: 200px;*/
}

ul.MenuBarVertical#Step1MenuBar {
	width: auto;
	float: left;
}

ul.MenuBarVertical#Step1MenuBar li {
	width: auto;
	display: block;
	float: none;
}
ul.MenuBarVertical#Step1MenuBar ul {
	width: auto;
}

ul.MenuBarVertical#Step1MenuBar ul li {
	width: auto;
	white-space: nowrap;
}

ul.MenuBarVertical#Step1MenuBar a.MenuBarItemSubmenu {
	padding: 0.5em 2em 0.5em 0.75em;
}


ul.MenuBarVertical#Step2MenuBar {
	width: auto;
	float: left;
}

ul.MenuBarVertical#Step2MenuBar li {
	width: auto;
	display: block;
	float: none;
	border-bottom: solid 1px #EEE;
}
ul.MenuBarVertical#Step2MenuBar li {
}
ul.MenuBarVertical#Step2MenuBar ul {
	width: auto;
}

ul.MenuBarVertical#Step2MenuBar ul li {
	width: auto;
	white-space: nowrap;
}

ul.MenuBarVertical#Step2MenuBar a.MenuBarItemSubmenu {
	padding: 0.5em 2em 0.5em 0.75em;
}

-->
</style>
</head>
<body>
<h3>Auto Width Vertical Menu Bar</h3>
<p>This page shows you how to modify the default styles for a Vertical Menu Bar, so that the menu items within the Menu Bar and its sub-menus are just wide enough to accomodate the longest menu item string. This sounds easy, but you also have to work around a specific IE layout bug.</p>
<p>Below, you'll notice that each CSS code sample starts off by including the default menu bar style sheet, and then declares a &lt;style&gt; block immediately after it, to override some of the default style properties set in the style sheet. The code is presented this way to show the minimal set of changes  that are necessary to accomplish the task. If you want these changes to affect more than one page, then you may want to integrate these changes directly into the style sheet.</p>
<p>This is what the standard Vertical Menu Bar looks like:</p>
<div class="liveSample">
	<ul id="DefaultStyleMenuBar1" class="MenuBarVertical">
		<li><a class="MenuBarItemSubmenu" href="#">Item 1</a>
			<ul>
				<li><a href="#">Item 1.1</a></li>
				<li><a href="#">Item 1.2</a></li>
				<li><a href="#">Item 1.3</a></li>
				<li><a href="#">Item 1.4</a></li>
			</ul>
		</li>
		<li><a href="#">Item 2</a></li>
		<li><a class="MenuBarItemSubmenu" href="#">Item 3</a>
			<ul>
				<li><a class="MenuBarItemSubmenu" href="#">Item 3.1</a>
					<ul>
						<li><a href="#">Item 3.1.1</a></li>
						<li><a href="#">Item 3.1.2</a></li>
						<li><a href="#">Item 3.1.3</a></li>
					</ul>
				</li>
				<li><a href="#">Item 3.2</a></li>
				<li><a href="#">Item 3.3</a></li>
				<li><a href="#">Item 3.4</a></li>
			</ul>
		</li>
		<li><a class="MenuBarItemSubmenu" href="#">Item4</a>
			<ul>
				<li><a class="MenuBarItemSubmenu" href="#">Item 4.1</a>
					<ul>
						<li><a href="#">Item 4.1.1</a></li>
						<li><a href="#">Item 4.1.2</a></li>
						<li><a href="#">Item 4.1.3</a></li>
					</ul>
				</li>
				<li><a href="#">Item 4.2</a></li>
				<li><a href="#">Item 4.3</a></li>
				<li><a href="#">Item 4.4</a></li>
			</ul>
		</li>
	</ul>
<script type="text/javascript">
<!--
var DefaultStyleMenuBar1 = new Spry.Widget.MenuBar("DefaultStyleMenuBar1", {imgRight:"../../widgets/menubar/SpryMenuBarRightHover.gif"});
//-->
</script>
</div>
<p>But when you start using long strings in both the menu bar and sub menus:</p>
<div class="liveSample">
	<ul id="DefaultStyleMenuBar2" class="MenuBarVertical">
		<li><a class="MenuBarItemSubmenu" href="#">Item 1</a>
			<ul>
				<li><a href="#">Item 1.1</a></li>
				<li><a href="#">Item 1.2</a></li>
				<li><a href="#">Item 1.3</a></li>
				<li><a href="#">This is a long menu item string!</a></li>
			</ul>
		</li>
		<li><a href="#">Item 2</a></li>
		<li><a class="MenuBarItemSubmenu" href="#">Item 3 - With a long menu item string!</a>
			<ul>
				<li><a class="MenuBarItemSubmenu" href="#">Item 3.1 - With a long menu item string!</a>
					<ul>
						<li><a href="#">Item 3.1.1</a></li>
						<li><a href="#">Item 3.1.2</a></li>
						<li><a href="#">This is a long menu item string!</a></li>
					</ul>
				</li>
				<li><a href="#">Item 3.2</a></li>
				<li><a href="#">Item 3.3</a></li>
				<li><a href="#">ThisIsALongMenuItemString!</a></li>
			</ul>
		</li>
		<li><a class="MenuBarItemSubmenu" href="#">Item4-WithAStringThatDoesNotWrap</a>
			<ul>
				<li><a class="MenuBarItemSubmenu" href="#">Item 4.1</a>
					<ul>
						<li><a href="#">Item 4.1.1</a></li>
						<li><a href="#">Item 4.1.2</a></li>
						<li><a href="#">WithAStringThatDoesNotWrap</a></li>
					</ul>
				</li>
				<li><a href="#">Item 4.2</a></li>
				<li><a href="#">Item 4.3</a></li>
				<li><a href="#">WithAStringThatDoesNotWrap</a></li>
			</ul>
		</li>
	</ul>
<script type="text/javascript">
<!--
var DefaultStyleMenuBar2 = new Spry.Widget.MenuBar("DefaultStyleMenuBar2", {imgRight:"../../widgets/menubar/SpryMenuBarRightHover.gif"});
//-->
</script>
</div>
<p>The menu items in both the menu bar and its submenus have a width property specified on them that give them a default with of 8.2em, which gives all of the menus a uniform look when the text fits neatly within that width, but it forces any text that is wider than that to wrap or hang out of the menu.</p>
<p>Removing the specified widths:</p>
<pre>
&lt;link href=&quot;../../widgets/menubar/SpryMenuBarVertical.css&quot; rel=&quot;stylesheet&quot; type=&quot;text/css&quot; /&gt;
&lt;style type=&quot;text/css&quot;&gt;
&lt;!--

/* Remove the fixed width off the menu bar itself. We float
 * the menu bar so that the browser sizes its width just enough
 * to fit its content. Another option, would be not to float the
 * menu bar, which will allow it to expand horizontally to fill
 * what ever container it is in.
 */

ul.MenuBarVertical {
	width: auto;
	float: left;
}

/* We want our menu items to expand to fill up its container,
 * so make sure it is a non-floated block element.
 */

ul.MenuBarVertical li {
	width: auto;
	display: block;
	float: none;
}

/* Remove any widths on sub menus. */

ul.MenuBarVertical ul {
	width: auto;
}

/* We don't want the text in any of our sub menus to
 * wrap, so we need to turn on &quot;nowrap&quot;.
 */

ul.MenuBarVertical ul li {
	width: auto;
	white-space: nowrap;
}

/* Now that our menus auto size horizontally, we need to
 * make sure that we have some space for any sub menu indicators
 * so they don't overlap with the text in the menu item.
 */

ul.MenuBarVertical a.MenuBarItemSubmenu {
	padding: 0.5em 2em 0.5em 0.75em;
}

--&gt;
&lt;/style&gt;
</pre>
<p>makes things a bit better:</p>
<div class="liveSample">
	<div class="sidebar">
	<ul id="Step1MenuBar" class="MenuBarVertical">
		<li><a class="MenuBarItemSubmenu" href="#">Item 1</a>
			<ul>
				<li><a href="#">Item 1.1</a></li>
				<li><a href="#">Item 1.2</a></li>
				<li><a href="#">Item 1.3</a></li>
				<li><a href="#">This is a long menu item string!</a></li>
			</ul>
		</li>
		<li><a href="#">Item 2</a></li>
		<li><a class="MenuBarItemSubmenu" href="#">Item 3 - With a long menu item string!</a>
			<ul>
				<li><a class="MenuBarItemSubmenu" href="#">Item 3.1 - With a long menu item string!</a>
					<ul>
						<li><a href="#">Item 3.1.1</a></li>
						<li><a href="#">Item 3.1.2</a></li>
						<li><a href="#">This is a long menu item string!</a></li>
					</ul>
				</li>
				<li><a href="#">Item 3.2</a></li>
				<li><a href="#">Item 3.3</a></li>
				<li><a href="#">ThisIsALongMenuItemString!</a></li>
			</ul>
		</li>
		<li><a class="MenuBarItemSubmenu" href="#">Item4-WithAStringThatDoesNotWrap</a>
			<ul>
				<li><a class="MenuBarItemSubmenu" href="#">Item 4.1</a>
					<ul>
						<li><a href="#">Item 4.1.1</a></li>
						<li><a href="#">Item 4.1.2</a></li>
						<li><a href="#">WithAStringThatDoesNotWrap</a></li>
					</ul>
				</li>
				<li><a href="#">Item 4.2</a></li>
				<li><a href="#">Item 4.3</a></li>
				<li><a href="#">WithAStringThatDoesNotWrap</a></li>
			</ul>
		</li>
	</ul>
	<div class="clearAll">&nbsp;</div>
	</div>
<script type="text/javascript">
<!--
var Step1MenuBar = new Spry.Widget.MenuBar("Step1MenuBar", {imgRight:"../../widgets/menubar/SpryMenuBarRightHover.gif"});
//-->
</script>
</div>
<p>But, now we have a problem in IE. The menu bar and sub menus now have white gaps between the menu items! This IE bug is very similar to the &quot;<a href="http://www.adobe.com/cfusion/communityengine/index.cfm?event=findByTextId&amp;productid=1&amp;textid=EXTRA_WHITESPACE_IN_LIST_LINKS&amp;loc=en_US">Extra Whitespace in List Links bug</a>&quot;, but the suggested workarounds don't seem to work as demonstrated in the &quot;<a href="AutoWidthHorizontalMenuBarSample.html">Auto Width Horizontal Menu Bar Sample</a>&quot;. The only workaround we've been able to find for this problem is to place a border-bottom on the element, so as a workaround, we will add a border-bottom to our menu item &lt;li&gt; elements that is the same color as the background of the menu, so it blends in with the background:</p>
<pre>
&lt;link href=&quot;../../widgets/menubar/SpryMenuBarVertical.css&quot; rel=&quot;stylesheet&quot; type=&quot;text/css&quot; /&gt;
&lt;style type=&quot;text/css&quot;&gt;
&lt;!--

/* Remove the fixed width off the menu bar itself. We float
 * the menu bar so that the browser sizes its width just enough
 * to fit its content. Another option, would be not to float the
 * menu bar, which will allow it to expand horizontally to fill
 * what ever container it is in.
 */

ul.MenuBarVertical {
	width: auto;
	float: left;
}

/* We want our menu items to expand to fill up its container,
 * so make sure it is a non-floated block element.
 *
 * The bottom border property is used here as a hack around
 * an IE6 bug that causes white gaps to appear between positioned
 * elements when a class is programatically placed on one of them,
 * even if that class is not defined, or contains no CSS properties
 * that have any visual impact.
 */

ul.MenuBarVertical li {
	width: auto;
	display: block;
	float: none;
	border-bottom: solid 1px #EEE;
}

/* Remove any widths on sub menus. */

ul.MenuBarVertical ul {
	width: auto;
}

/* We don't want the text in any of our sub menus to
 * wrap, so we need to turn on &quot;nowrap&quot;.
 */

ul.MenuBarVertical ul li {
	width: auto;
	white-space: nowrap;
}

/* Now that our menus auto size horizontally, we need to
 * make sure that we have some space for any sub menu indicators
 * so they don't overlap with the text in the menu item.
 */

ul.MenuBarVertical a.MenuBarItemSubmenu {
	padding: 0.5em 2em 0.5em 0.75em;
}

--&gt;
&lt;/style&gt;
</pre>
<p>makes things a bit better:</p>
<div class="liveSample">
	<div class="sidebar">
	<ul id="Step2MenuBar" class="MenuBarVertical">
		<li><a class="MenuBarItemSubmenu" href="#">Item 1</a>
			<ul>
				<li><a href="#">Item 1.1</a></li>
				<li><a href="#">Item 1.2</a></li>
				<li><a href="#">Item 1.3</a></li>
				<li><a href="#">This is a long menu item string!</a></li>
			</ul>
		</li>
		<li><a href="#">Item 2</a></li>
		<li><a class="MenuBarItemSubmenu" href="#">Item 3 - With a long menu item string!</a>
			<ul>
				<li><a class="MenuBarItemSubmenu" href="#">Item 3.1 - With a long menu item string!</a>
					<ul>
						<li><a href="#">Item 3.1.1</a></li>
						<li><a href="#">Item 3.1.2</a></li>
						<li><a href="#">This is a long menu item string!</a></li>
					</ul>
				</li>
				<li><a href="#">Item 3.2</a></li>
				<li><a href="#">Item 3.3</a></li>
				<li><a href="#">ThisIsALongMenuItemString!</a></li>
			</ul>
		</li>
		<li><a class="MenuBarItemSubmenu" href="#">Item4-WithAStringThatDoesNotWrap</a>
			<ul>
				<li><a class="MenuBarItemSubmenu" href="#">Item 4.1</a>
					<ul>
						<li><a href="#">Item 4.1.1</a></li>
						<li><a href="#">Item 4.1.2</a></li>
						<li><a href="#">WithAStringThatDoesNotWrap</a></li>
					</ul>
				</li>
				<li><a href="#">Item 4.2</a></li>
				<li><a href="#">Item 4.3</a></li>
				<li><a href="#">WithAStringThatDoesNotWrap</a></li>
			</ul>
		</li>
	</ul>
	<div class="clearAll">&nbsp;</div>
	</div>
<script type="text/javascript">
<!--
var Step2MenuBar = new Spry.Widget.MenuBar("Step2MenuBar", {imgRight:"../../widgets/menubar/SpryMenuBarRightHover.gif"});
//-->
</script>
</div>
<p>&nbsp;</p>
</body>
</html>
